package com.zhao.composite;

import com.zhao.component.MenuComponent;

import javax.management.OperationsException;
import java.util.ArrayList;
import java.util.List;

public class Menu extends MenuComponent {

    private List<MenuComponent> menuComponents = new ArrayList<MenuComponent>();

    public Menu(String name, Integer level) {
        super.name = name;
        super.level = level;
    }

    public void add(MenuComponent menuComponent){
        menuComponents.add(menuComponent);
    }

    public void remove(Integer index){
        menuComponents.remove(index);
    }

    @Override
    public void print() {
        for (int i = 0 ; i < level; i++) {
            System.out.print("-");
        }
        System.out.println(name);
        for (MenuComponent menuComponent : menuComponents) {
            menuComponent.print();
        }
    }
}
